import jsonschema

schema1 = {
    "type": "object",  # 整个接受的内容的类型 规则用json写，空为null
    "properties": {
        "name": {"type": "string"},  # 用花括号括起来的name类型为string，注意格式
        "size": {"const": "big"},  # const 判断具体值是否相同
        "age": {"pattern": "[0-99]"},  # 正则表达式 0-99之间
        "isman": {"const": True},
        "info": {"type": "array"},
        "weight": {"const": 72.1},
        "phone": {"pattern": "^1[3-9]\d{9}$"}, #手机号正则化
        "data": {"type": "object",
                 "properties": {"data_1": {"type": "string"},
                                "height": {"type": "number"}},
                 "required": ["data_1", "height"]
                 },
    },
    "required": ["name", "age", "isman", "info", "data"]
}
emp = {
    "name": "宁宁",
    "size": "big",
    "age": 15,
    "isman": True,
    "phone": "17544442222",
    "info": [1, 2, 3],  # 数组类型
    "weight": 72.1,
    "data": {
        "data_1": "Xenonning",
        "height": 178.5
    }
}
print(jsonschema.validate(instance=emp, schema=schema1))
